import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import set from '@dfeidao/atom-web/local/set';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from "@dfeidao/atom-web/render/render";
import set_node_cls from '@dfeidao/atom-web/ui/set-node-cls';
import p001 from './p001';


export default async function a001(fd: IFeidaoAiBrowserComponent, no: string) {
	// todo
	const n = fd.data.node.querySelector<HTMLDivElement>('[data-id="update"]');
	set_node_cls(n, 'display-n', false);

	console.log(no, 'zj03');

	const res1 = await nodejs<{ res: Array<{ plan_cla_attr_no: string; plan_type_no: string; take_effect: number; }>; res1: Array<{}> }>('plan-cb/zj-000003/s001', {
		plan_no: no
	});
	console.log('res1', res1);
	// 计划分类
	// const n1 = fd.data.node.querySelector<HTMLSelectElement>('[data-id="plan"]');
	// const v = n1.value;
	// console.log(v, 'data-id="plan"');


	const res2 = await nodejs<Array<{}>>('plan-cb/zj-000002/s002', {
		plan_cla_attr_no: res1.res[0].plan_cla_attr_no
	});
	const render_data = Object.assign(res1, { res2 });
	console.log('render_data', render_data);
	const plan = res1.res[0].plan_cla_attr_no;
	const type = res1.res[0].plan_type_no;
	set(fd, 'no', { plan, type });

	if (res1.res[0].take_effect === 0) {
		// 可编辑
		render(fd, render_data, p001, 'p001', 'inner');
	} else {
		// 不可编辑  去掉保存，确认，删除图标
		render(fd, render_data, p001, 'p001', 'inner');
	}




	// render(fd, res, p001, 'p001', 'inner');
	// const f = fd.data.node.querySelector('[data-id="file"]') as HTMLSpanElement;
	// f.setAttribute('class', 'display-ib color-red');
}
